#include "commonsettting.h"

#include <QComboBox>
#include <QGroupBox>
#include <QLabel>
#include <QVBoxLayout>

commonSettting::commonSettting(QWidget *parent)
    : QWidget{parent}
    , startCheckBox(new QCheckBox())
    , languageChoose(new QComboBox())
    , preLanguageIndex(0)
{
    QVBoxLayout *mainVBoxLayout = new QVBoxLayout(this);
    mainVBoxLayout->setObjectName("mainVBoxLayout");
    mainVBoxLayout->setSpacing(20);
    this->setContentsMargins(10, 8, 10, 10);
    //水平布局
    QHBoxLayout *hboxLayout = new QHBoxLayout();
    hboxLayout->setObjectName("hboxLayout");
    //设置对齐方式
    hboxLayout->setAlignment(Qt::AlignLeft);

    //checkBox加入
    startCheckBox->setObjectName("startCheckBox");
    startCheckBox->setText("开机时启动爱科会议");
    QFont font = startCheckBox->font();
    font.setFamily("Microsoft YaHei");
    font.setPointSize(10);
    startCheckBox->setFont(font);
    hboxLayout->addWidget(startCheckBox);

    //将这个水平局部加入到主布局中
    mainVBoxLayout->addLayout(hboxLayout);

    QVBoxLayout *VBoxLayout = new QVBoxLayout();
    VBoxLayout->setSpacing(2);
    QLabel *language = new QLabel();
    language->setObjectName("language");
    language->setText("语言");
    language->setAlignment(Qt::AlignLeft);
    QFont font2 = language->font();
    font2.setBold(true);
    font2.setFamily("Microsoft YaHei");
    font2.setPointSize(10);
    //想要抗锯齿的话，就需要自定义Label，后续完成
    language->setFont(font2);
    VBoxLayout->addWidget(language);
    VBoxLayout->setAlignment(Qt::AlignTop);

    //新加入一个comBox
    languageChoose->setObjectName("languageChoose");
    languageChoose->addItem("简体中文");
    languageChoose->addItem("English");

    // 设置边框样式
    languageChoose->setStyleSheet("QComboBox {"
                                  "    border: 1px solid gray;" // 边框宽度和颜色
                                  "    border-radius: 5px;"     // 圆角半径
                                  "    padding: 1px 18px 1px 3px;" // 内边距，确保文本不与边框重叠
                                  "    min-width: 150px;" // 最小宽度
                                  "}"
                                  "QComboBox::drop-down {"
                                  "subcontrol-position: padding;"
                                  "subcontrol-position: top right;"
                                  "width: 16px;"
                                  "border: none; /* 尺边框 */"
                                  "border-image: url(:/resources/down-arrow.png) ;"
                                  "}");

    VBoxLayout->addWidget(languageChoose);

    mainVBoxLayout->addLayout(VBoxLayout);

    //该窗口设置固定大小
    //this->setFixedSize(QSize(500, 400));
    connect(startCheckBox, &QCheckBox::stateChanged, this, &commonSettting::onCheckBoxStateChange);
    connect(languageChoose, &QComboBox::activated, this, &commonSettting::onComboxBoxActivated);
}
// QTC_TEMP
void commonSettting::onCheckBoxStateChange(int state)
{
    qDebug() << state;
    //这里也没有加开机自启动的逻辑
}

void commonSettting::onComboxBoxActivated(int index)
{
    if (index != preLanguageIndex) {
        qDebug() << "默认语言已改变";
        //还没有增加具体的逻辑
    }
    preLanguageIndex = index;
}
